package com.atwulidun.chainofresponsibiliity22;

public class ChainOfResponsibilityDemo {
    public static void main(String[] args) {
        // 创建一个购买需求
        PurchaseRequest purchaseRequest = new PurchaseRequest("购买新电脑请求", 1000);

        // 创建各个处理人
        // 系主任
        Approver departmentApprover = new DepartmentApprover("系主任");
        // 院长
        Approver collegeApprover = new CollegeApprover("院长");
        // 副校长
        Approver vicePrincipalApprover = new VicePrincipalApprover("副校长");
        // 校长
        Approver principalApprover = new PrincipalApprover("校长");

        // 设置每个处理人的下一次处理人，注意：设置成环形
        departmentApprover.setSuccessor(collegeApprover);
        collegeApprover.setSuccessor(vicePrincipalApprover);
        vicePrincipalApprover.setSuccessor(principalApprover);
        principalApprover.setSuccessor(departmentApprover);

        // 由系主任开始处理请求
        departmentApprover.processRequest(purchaseRequest);
        // 由副校长开始处理请求
        vicePrincipalApprover.processRequest(purchaseRequest);
    }
}
